package comu.hnevc.zh.training;

import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

public class FlashActivity extends AppCompatActivity {
  ViewPager viewPager;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_flash);
        viewPager=findViewById(R.id.viewpage);
        ArrayList<View> mViewList = new ArrayList<View>();
        LayoutInflater lf = getLayoutInflater().from(FlashActivity.this);
        View view1 = lf.inflate(R.layout.view1, null);
        View view2 = lf.inflate(R.layout.view2, null);
        View view3 = lf.inflate(R.layout.view3, null);
        View view4 = lf.inflate(R.layout.view4, null);
        mViewList.add(view1);
        mViewList.add(view2);
        mViewList.add(view3);
        mViewList.add(view4);
        viewPager.setAdapter(new ViewPagerAdatper(mViewList));


    }
    public class ViewPagerAdatper extends PagerAdapter {
        private List<View> mViewList ;

        public ViewPagerAdatper(List<View> mViewList ) {
            this.mViewList = mViewList;
        }

        @Override
        public int getCount() {
            return mViewList.size();
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view==object;
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            container.addView(mViewList.get(position));
            return mViewList.get(position);
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView(mViewList.get(position));
        }
    }

}
